package com.alesj.newsfeed.bool.impl;

import java.util.List;
import java.util.Set;

import com.alesj.newsfeed.bool.Condition;

/**
 * @author <a href="mailto:ales.justin@gmail.com">Ales Justin</a>
 */
public class OrCondition<T> implements Condition<T> {    
    private List<Condition<T>> tokens;

    public OrCondition(List<Condition<T>> tokens) {
        this.tokens = tokens;
    }

    @SuppressWarnings("unchecked")
    public Set<T> execute() {
        Set<T> result = tokens.get(0).execute();
        for(int i = 1; i < tokens.size(); i++) {
            result = Or.INSTANCE.execute(result, tokens.get(i).execute());
        }
        return result;
    }
}
